package top.hepingan.java.config;

import cn.dev33.satoken.stp.StpInterface;
import org.springframework.stereotype.Component;
import top.hepingan.java.entity.User;
import top.hepingan.java.mapper.UserMapper;
import top.hepingan.java.utils.UserUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Component
public class StpInterfaceConfig implements StpInterface {

    private final UserMapper userMapper;

    public StpInterfaceConfig(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return List.of();
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 本 list 仅做模拟，实际项目中要根据具体业务逻辑来查询角色
        List<String> list = new ArrayList<String>();
        User user = userMapper.selectById(UserUtils.getCurrentLoginId());
        if (Objects.equals(user.getRole(), "admin")){
            list.add("admin");
        }
        return list;
    }
}
